package com.bootdo.xiao.suggest;

/**
 * @Auther: liuj
 * @Date: 2019/6/17 17:46
 * @Description:建议40：匿名类的构造函数很特殊
 */
public class Suggest40 {
    public static void main(String[] args){
        Calculator c1 = new Calculator(5,13){
            {
                setOps(Ops.ADD);
            }
        };

        System.out.println(c1.getResult());
    }
}

enum Ops{
    ADD,
    SUB
}

class Calculator{
    private int i, j, result;

    public Calculator(){

    }

    public Calculator(int _i, int _j){
        i = _i;
        j = _j;
    }

    protected void setOps(Ops _ops){
        result = _ops.equals(Ops.ADD) ? i+j : i-j;
    }

    public int getResult(){
        return result;
    }

}


